<?php
/*
	申请成为代理商
	如果已申请，但尚未审核通过，则页面显示请耐心等待管理员审核！
	如果已申请，且审核通过，则显示审核通过，并提供按钮前往代理中心
	如果审核不通过，则显示审核不通过原因
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['worker']=$this->model('model')->checkworker();
if($_RQ['op']=='main'){
	$return['ischecklogin']=model('jy_weishop/member')->checklogin('','','','',true);
	$return['goods']=pdo_getall('jy_shopworker_goods',array('status'=>1,'uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$id=intval($_RQ['id']);
	if($id){
		$return['post']=pdo_get('jy_shopworker_orderlog',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$return['post']=array();
	}
	set_html('title','成交录入');
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	if(!$post['goodsid']){
		exi('请选择商品！','error');
	}
	if(!$post['price']){
		exi('请输入成交价！','error');
	}
	$goodsinfo=pdo_get('jy_shopworker_goods',array('id'=>$post['goodsid'],'uniacid'=>$_SESSION['uniacid']));
	$pay_time = strtotime($post['pay_time']);
	$pay_time = $pay_time?:time();
	$data=array(
		'goodsid'=>$post['goodsid'],
		'goodsinfo'=>ijson_encode($goodsinfo),
		'workerid'=>$return['worker']['id'],
		'price'=>$post['price'],
		'benprice'=>$goodsinfo['benprice'],
		'payimg'=>$post['payimg'],
		'ordersn'=>$post['ordersn'],
		'remark'=>$post['remark'],
		'cname'=>$post['cname'],
		'username'=>$post['username'],
		'mobile'=>$post['mobile'],
		'pay_time'=>$pay_time,
		'status'=>0,
	);
	if($post['id']){
		pdo_update('jy_shopworker_orderlog',$data,array('id'=>$post['id'],'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=time();
		pdo_insert('jy_shopworker_orderlog',$data);
	}
	exi('提交成功！请耐心等待主管审核！','','/orderlog/');
}